
// return the count of substr in the str
macro StrCnt(str, substr)
{
	str_len=strlen(str)
	substr_len=strlen(substr)
	
	if(str_len<substr_len)
		return 0
	
	search_len=str_len-substr_len+1;
	cnt=0
	i=0
	while(i<search_len)
	{
		j=0
		while(j<substr_len)
		{
			if(str[i+j]!=substr[j])
				break;
			j=j+1
		}
		if(j==substr_len)
		{
			cnt=cnt+1
			j=j-1
		}
		i=i+1
		i=i+j
	}
	return cnt
}

// insert one buffer(from lnSrcBgn to LnSrcEnd) to another buffer(at lnDes)
macro InsBuf2Buf(hbufDes, lnDes, hbufSrc, lnSrcBgn, LnSrcEnd)
{
	if(-1==lnDes){
		lnDes=GetBufLineCount(hbufDes)
	}
	
	if(-1==LnSrcEnd){
		LnSrcEnd=GetBufLineCount(hbufSrc)
	}
	
	while(lnSrcBgn<LnSrcEnd){
		s=GetBufLine(hbufSrc, lnSrcBgn)
		InsBufLine(hbufDes, lnDes, s)
		
		lnSrcBgn=lnSrcBgn+1
		lnDes=lnDes+1
	}

	return lnDes
}

macro SelectRegion(hbuf, lnStart, chStart, lnEnd, chEnd)
{
	SetBufIns(hbuf, lnStart, chStart);
	Toggle_extend_mode;
	SetBufIns(hbuf, lnEnd, chEnd);
	Toggle_extend_mode;
}


